-
Notifications
You must be signed in to change notification settings - Fork 273
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Configuration: refactor network configuration, migrate to chainId, remove unnecessary connectivity polling #1485
Conversation
@@ -189,7 +184,7 @@ function AccountModule() { | |||
providerInfo={providerInfo} | |||
walletConnectionStatus={walletConnectionStatus} | |||
walletListening={walletListening} | |||
walletOnline={walletListening} | |||
walletOnline={walletOnline} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure, but I think this should be a fix 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whoops! Haha I can definitely tell you this is a fix. 😆
@@ -71,8 +41,7 @@ export function useWalletConnectionDetails( | |||
isWalletAndClientSynced | |||
|
|||
const defaultOkConnectionDetails = { | |||
connectionMessage: `Connected to ${walletNetworkName}`, | |||
connectionMessageLong: `Connected to Ethereum ${walletNetworkName} Network`, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We weren't using this key as far as I could tell
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 to this; we definitely want shorter messages for the short connection message.
@@ -32,17 +37,20 @@ export const networkConfigs = { | |||
portisDappId ? { id: 'portis', conf: portisDappId } : null, | |||
].filter(p => p), | |||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought the above renamings were more clear:
endpoints
communicates that this is a network-specific URL much better thannodes.defaultEth
environment
communicates that this is what will be available in theenvironment.js
file much better thansettings
does (it's not really network settings anymore)
@@ -105,14 +104,14 @@ | |||
"bundlewatch": "bundlewatch", | |||
"start": "node scripts/start", | |||
"start:local": "node scripts/launch-local", | |||
"start:mainnet": "cross-env ARAGON_ETH_NETWORK_TYPE=main npm start", | |||
"start:mainnet": "cross-env ARAGON_ETH_NETWORK_TYPE=ethereum npm start", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've started renaming our internal references to "main" or "mainnet" to "Ethereum", as "mainnet" is not descriptive enough (e.g. xDai has a mainnet, Aragon Chain will have a mainnet).
@@ -45,18 +45,6 @@ const INITIAL_DAO_STATE = { | |||
repos: [], | |||
} | |||
|
|||
const SELECTOR_NETWORKS = [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This felt like an odd place to configure the available networks during onboarding, so I've moved it out into the /onboarding
folder as static configuration.
componentDidMount() { | ||
// Only the default, because the app can work without the wallet | ||
pollConnectivity([web3Providers.default], connected => { | ||
this.setState({ connected }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As far as I could tell, this connected
state is actually not used anymore now that we do the block polling in the Account module.
Good riddance—this was spiking our API requests to ETH nodes!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚀
? `select the ${sanitizeNetworkType(network.type)} network` | ||
: 'unlock your account' | ||
} in ${getProviderString( | ||
{`Please unlock your account in ${getProviderString( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar to the Account module, I've simplified places where we check the connect account's network vs. the expected network as the user currently can never have their account enabled on a different network.
@@ -29,28 +27,15 @@ function ValidateWalletWeb3({ | |||
) | |||
} | |||
|
|||
if (isTransaction && walletNetworkType !== networkType) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar to above, this state is now impossible to be in
}) | ||
const getStoredList = (daoAddress, account) => | ||
new StoredList( | ||
`activity:chainId-${network.chainId}:${daoAddress}:${account}`, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that this key change will reset any saved activities a user may have held.
In particular, I found it better to use an address here rather than the domain—the same organization can hold multiple (or no) ENS domains.
@@ -7,7 +7,7 @@ import { addressesEqual } from '../web3-utils' | |||
|
|||
const FavoriteDaosContext = React.createContext() | |||
|
|||
const storedList = new StoredList(`favorite-daos:${network.type}`) | |||
const storedList = new StoredList(`favorite-daos:chainId-${network.chainId}`) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar to above, this will reset any saved favourited DAOs.
@@ -17,7 +17,6 @@ import { RoutingProvider } from './routing' | |||
import { ConsoleVisibleProvider } from './apps/Console/useConsole' | |||
import initializeSentryIfEnabled from './sentry' | |||
import { HelpScoutProvider } from './components/HelpScoutBeacon/useHelpScout' | |||
import { ClientBlockNumberProvider } from './components/AccountModule/useClientBlockNumber' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As far as I could tell, there were no uses of this provider's value, as we only show the wallet's sync block (and each connectivity check directly calculates the block drift between the wallet and the read provider).
@@ -100,12 +100,17 @@ export function getLocalChainId() { | |||
return getLocalSetting(LOCAL_CHAIN_ID) || 1337 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've taken the liberty of renaming some of the exposed methods to be more clear, without changing the underlying environment variables.
At a future point in time (e.g. as we evaluate snowpack / etc), we can make breaking changes :).
export function getNetworkConfig(id) { | ||
const networkConfig = networkConfigurations[id] | ||
if (!networkConfig) { | ||
throw new Error(`Unsupported network '${id}'`) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that I've opted to entirely remove the unsupported network
configuration.
It's impossible to statically know what chain id to expect in that case, and it's likely better the app just blows up entirely than pretend things are OK.
@@ -266,7 +266,6 @@ export const WalletType = PropTypes.shape({ | |||
enable: PropTypes.bool.isRequired, | |||
connected: PropTypes.bool.isRequired, | |||
isContract: PropTypes.bool.isRequired, | |||
networkType: PropTypes.string.isRequired, | |||
providerInfo: PropTypes.object.isRequired, | |||
web3: PropTypes.object.isRequired, | |||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This type doesn't seem to be used anywhere, but is perhaps still useful for the sake of documentation?
Anyhow, I've updated it with our wallet.js
changes.
@@ -120,12 +119,7 @@ export default { | |||
const adjustedDuration = new BN(duration).toString() | |||
const votingSettings = [adjustedSupport, adjustedQuorum, adjustedDuration] | |||
|
|||
// Rinkeby has its gas limit capped at 7M, so some larger 6.5M+ transactions are |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Things have changed a lot since Sept. 2019; Rinkeby now has a 10M gas limit.
@@ -1,12 +1,61 @@ | |||
import tokens from '@aragon/templates-tokens' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've removed this import and just inlined the contents so we can control them better.
Particularly, the import used the network's name rather than chain ID (and to be honest, that package is not particularly helpful).
@@ -145,13 +146,18 @@ const gasPriceApi = 'https://ethgasstation.info/json/ethgasAPI.json' | |||
export async function getGasPrice({ | |||
mainnet: { safeMinimum = '3', disableEstimate } = {}, | |||
} = {}) { | |||
if (network.type !== 'main') { | |||
// Hardcode 10 for non-mainnet networks | |||
if (network.chainId === CHAIN_IDS.XDAI) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There does not appear to be a public API providing gas price estimates on xDai yet... which is probably fine given there are almost no transactions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Really solid PR! lots of good changes in here 🚀 🔥 . I've left some comments on areas which stuck out, the main one being how we are accessing endpoints and making sure it's working as expected.
const ts = tokens[network] | ||
const depositer = new web3.eth.Contract(tokens.depositerABI, ts.depositer) | ||
export default (web3, financeAddr, from) => { | ||
if (!testTokensEnabled) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (!testTokensEnabled) { | |
if (!testTokensEnabled()) { |
Think we need to call this.
@@ -124,37 +120,40 @@ Network.propTypes = { | |||
|
|||
const useNetwork = wrapper => { | |||
const [networkError, setNetworkError] = useState(null) | |||
const [ethNode, setEthNodeValue] = useState(defaultEthNode) | |||
const [ethEndpoint, setEthEndpointValue] = useState(network.endpoints.read) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure this is correct, looks like network
is an alias for networkConfig.environment
which doesn't contain the endpoints.
src/network-config.js
Outdated
endpoints: { | ||
read: providedDefaultEthNode || 'wss://mainnet.eth.aragon.network/ws', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Much prefer this naming! ✨ wonder if eth
is more suitable than read
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AFAIK read's used as we separate our "read" provider for fetching info, from our write provider (the wallet provider). I actually think this is more clear than eth
. 😃
const PROTECTED_CHAIN_IDS = new Proxy(CHAIN_IDS, { | ||
get(target, property) { | ||
if (property in target) { | ||
return target[property] | ||
} else { | ||
throw new Error(`Chain ID '${property}' not supported`) | ||
} | ||
}, | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✨
rinkeby: new Map( | ||
|
||
// Ethereum Rinkeby | ||
[CHAIN_IDS.ETHEREUM]: new Map( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[CHAIN_IDS.ETHEREUM]: new Map( | |
[CHAIN_IDS.RINKEBY]: new Map( |
]) | ||
const UNKNOWN_NETWORK_BLOCK_TIME = 2 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just curious – Is this still necessary considering the previous change to unsupported network
?
componentDidMount() { | ||
// Only the default, because the app can work without the wallet | ||
pollConnectivity([web3Providers.default], connected => { | ||
this.setState({ connected }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚀
@@ -71,8 +41,7 @@ export function useWalletConnectionDetails( | |||
isWalletAndClientSynced | |||
|
|||
const defaultOkConnectionDetails = { | |||
connectionMessage: `Connected to ${walletNetworkName}`, | |||
connectionMessageLong: `Connected to Ethereum ${walletNetworkName} Network`, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Boom! Quite the changes but all of these things are super clear now. :) Left some comments:
chainId: 1, | ||
name: 'Mainnet', | ||
name: 'Ethereum', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I dig this new naming a lot; but maybe it can be clearer that this is the Ethereum mainnet network?
@@ -189,7 +184,7 @@ function AccountModule() { | |||
providerInfo={providerInfo} | |||
walletConnectionStatus={walletConnectionStatus} | |||
walletListening={walletListening} | |||
walletOnline={walletListening} | |||
walletOnline={walletOnline} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whoops! Haha I can definitely tell you this is a fix. 😆
@@ -71,8 +41,7 @@ export function useWalletConnectionDetails( | |||
isWalletAndClientSynced | |||
|
|||
const defaultOkConnectionDetails = { | |||
connectionMessage: `Connected to ${walletNetworkName}`, | |||
connectionMessageLong: `Connected to Ethereum ${walletNetworkName} Network`, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 to this; we definitely want shorter messages for the short connection message.
const PROTECTED_CHAIN_IDS = new Proxy(CHAIN_IDS, { | ||
get(target, property) { | ||
if (property in target) { | ||
return target[property] | ||
} else { | ||
throw new Error(`Chain ID '${property}' not supported`) | ||
} | ||
}, | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✨
@@ -360,12 +352,10 @@ class SignerPanel extends React.PureComponent { | |||
> | |||
<Screen> | |||
<ValidateWalletWeb3 | |||
hasWallet={Boolean(walletWeb3)} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I definitely don't remember exactly from where the account
and other use-wallet
related props are being drilled from, but we could definitely pass the connected
prop corresponding to the wallet from use-wallet
.
} | ||
|
||
export function testTokensEnabled() { | ||
return !!AIRDROP_TOKENS[network.chainId] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can make this nicer by applying Boolean()
. :)
This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for contributing to Aragon! 🦅 |
Recommended to review commit by commit—each commit is meant to be a separate PR, but due to changes stacking from one commit to each other, and the possible conflicts that may arise from one PR to another, I've decided to keep all the changes in a single PR.
At the moment, this PR has not been thoroughly tested! Since so many of the changes are built on top of each other, my plan is to do a thorough round of testing after a few more sets of changes (coming soon).
Changes:
The Ethereum network
,The xDai network
,The Ethereum Rinkeby test network
, etc.main
toethereum
network.type
withnetwork.chainId
(fixes Removenetwork.type
#1472)Note: we are not able to completely eliminate
network.type
yet, as there are some APIs from aragonUI that need to be updated (see https://github.com/aragon/aragon-ui/pull/788).